package com.javabasic.topic;

/**
 * @author mir.xiong
 * @version 1.0
 * @description
 * @see
 * @since Created by work on 2022/1/8 11:47 下午
 */
public class SearchAlgorithm {

    public int binarySearch(int[] array, int target) {
        int left = 0, right = array.length-1, mid;
        while (left <= right) {
            mid = left + ((right-left)>>1);
            if (array[mid] == target) {
                return mid;
            } else if (array[mid] > target) {
                right = mid-1;
            } else {
                left = mid + 1;
            }
        }
        return left;
    }

    public int lowerBound(int[] array, int target) {
        int left = 0, right = array.length-1, mid;
        while (left <= right) {
            mid = left + ((right-left)>>1);
            if (array[mid] > target) {

            }
        }
        return left;
    }
}
